﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using Newtonsoft.Json;
using System.Text;
using System.IO;
using Newtonsoft.Json.Converters;
using ServerPicture.Models;

namespace ServerPicture.Controllers
{
    public class TagController : ApiController
    {
        //chú ý...là tên biến của method pải đúng như trong router mapping vd: api/{controller}/{action}/{id}=>   GetAllProducts(id)

        //get all photo
        public IEnumerable<Models.Tag> GetAllTag()
        {
            IList<Models.Tag> photo = new List<Models.Tag>();
            DatabaseDataContext db = new DatabaseDataContext();
            var list = from p in db.Tags
                       orderby p.Tag_Name ascending
                       select new Models.Tag
                       {
                           Tag_ID = p.Tag_ID,
                           Tag_Name = p.Tag_Name
                       };
            photo = list.ToList();
            if (photo == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            return photo;
        }
      
      
    }
}
